package com.healthbox.resultsservice.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyTime {
    public static String getCurrTimeAsString(){
        Date date = new Date();//获得系统时间.
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
        String nowTime = sdf.format(date);
        return nowTime;
    }

    public static String dateTime2String(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
        String time = sdf.format(date);
        return time;
    }

    public static String date2String(java.sql.Date date){
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
        String time = sdf.format(date);
        return time;
    }

    public static Date getCurrTimeAsDate(){
        Date date = new Date();//获得系统时间.
        return date;
    }

    public static java.sql.Date stringToDate(String str) {
        SimpleDateFormat dateFormatHiddenHour = new SimpleDateFormat("yyyy-MM-dd");
        java.sql.Date date = null;
        try {
            String s = dateFormatHiddenHour.format(dateFormatHiddenHour.parse(str));
            date = java.sql.Date.valueOf(s);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

}
